package demo00;

/**
 * 多个线程共享同一个资源的情况演示
 */
public class ThreadDemo04 {

    public static void main(String[] args) {
        TS1 t1 = new TS1();

        Thread thread1 = new Thread(t1);
        Thread thread2 = new Thread(t1);

        thread1.start();
        thread2.start();
    }
}

class TS1 implements Runnable{

    int count = 0;

    @Override
    public void run() {
        while (true) {
            System.out.println(Thread.currentThread().getName() + ": hello world " + (++count));
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            if (count == 8) {
                break;
            }
        }
    }
}
